import {getNotice,deleteNotice,addNotice,noticeInfo} from '@/api/notice.js'
const state = {

}
const mutations = { // mutations改变state中的数据
    NULL:()=>{}
}
const actions={
    getNotice({commit},data){
        const info={
            collegeId:data.collegeId,
            currentPage:data.currentPage,
            rows:data.rows,
            token:data.token,
        };
        return new Promise((resolve, reject) => {
            getNotice(info).then( data => {
                if(data.code === 1){ // 获取通知成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    deleteNotice({commit},data){
        return new Promise((resolve, reject) => {
            deleteNotice({noticeId:data.noticeId,token:data.token}).then( data => {
                if(data.code === 1){ // 删除通知成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    addNotice({commit},data){
        return new Promise((resolve, reject) => {
            const noticeInfo={
                noticeInfo:data.noticeInfo,
                token:data.token,
            };
            addNotice(noticeInfo).then( data => {
                if(data.code === 1){ // 添加通知成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    noticeInfo({commit},data){
        return new Promise((resolve,reject)=>{
            noticeInfo({noticeId:data.noticeId,token:data.token}).then(data=>{
                if(data.code === 1){ // 获取通知详情
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
